package com.ruoyi.project.manage.service.impl;



import com.ruoyi.project.manage.SavePrescriptionVO;

import com.ruoyi.project.manage.domain.HisSavecase;
import com.ruoyi.project.manage.domain.HisSaveprescription;
import com.ruoyi.project.manage.mapper.HisSaveCaseMapper;

import com.ruoyi.project.manage.service.HisSaveCaseService;
import com.ruoyi.project.manage.service.HisSaveCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class HisSaveCaseImpl implements HisSaveCaseService {
    @Autowired
    private HisSaveCaseMapper hisSaveCaseMapper;




    @Override
    public List<SavePrescriptionVO> findOne(Long sRegistrationFormId,Integer checkModel) {
        //获取患者表和病例表
        List<HisSavecase> hisSavecaseList = hisSaveCaseMapper.selectOne(sRegistrationFormId);
        List<SavePrescriptionVO> voList = new ArrayList<>();
        for (HisSavecase hisSavecase:hisSavecaseList){
            SavePrescriptionVO vo = new SavePrescriptionVO();
            Long registrationFormId = hisSavecase.getsRegistrationFormId();  //挂号单id
            Long caseNumber = hisSavecase.getsCaseNumber();//病例编号
            Long sid = hisSavecase.getHisPatientbank().getsId();//患者的主键id
            String sname = hisSavecase.getHisPatientbank().getsName();  //患者姓名
            String remark = hisSavecase.getHisPatientbank().getsRemark();  //患者检查备注
            //根据患者主键id查询病例表
            String chm = null;
            if (checkModel != null && checkModel == 1){
                chm = "乙肝五项";
            }else if (checkModel!= null && checkModel == 2){
                chm = "血常规";
            }else if (checkModel!= null && checkModel == 3){
                chm = "CT";
            }else if (checkModel!= null && checkModel == 4){
                chm = "X光";
            }
            HisSaveprescription hisSaveprescription = hisSaveCaseMapper.selectBySid(sRegistrationFormId, chm);
            if (hisSaveprescription!=null){
                long aid = hisSaveprescription.getaId();    //病例表主键id
                String aname = hisSaveprescription.getaName();     //患者项目名称
                vo.setAId(aid);
                vo.setSId(sid);
                vo.setAName(aname);
                vo.setSName(sname);
                vo.setSCaseNumber(caseNumber);
                vo.setSRegistrationFormId(registrationFormId);
                vo.setSRemark(remark);
                vo.setAZhuangtai(hisSaveprescription.getaZhuangtai());
                voList.add(vo);
            }

        }

        return voList;
    }


    @Override
    public Boolean updateSatus(Integer aId) {
        if (aId == null){
            return  false;
        }
        try {
            Integer i =   hisSaveCaseMapper.updateSatus(aId);
            if (i>0){
                return true;
            }else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

   /* //检查结果录入的查询
    @Override
    public Map<String, Object> findOne02(String registrationid) {
        //获取患者表和病例表
        Savecase savecase = saveCaseMapper.selectOne02(registrationid);

        String registrationid1 = savecase.getRegistrationid();  //挂号单id
        String casenumber = savecase.getCasenumber();   //病例编号
        int sid = savecase.getPatientbank().getSid();   //患者的主键id
        String sname = savecase.getPatientbank().getSname();    //患者姓名
        String sremark = savecase.getPatientbank().getSremark();    //患者检查备注

        //根据患者主键id查询病例表
        SavePrescription savePrescription = saveCaseMapper.selectBysid(sid);
        int aid = savePrescription.getAid();    //病例表主键id
        String aname = savePrescription.getAname();     //患者项目名称
        String atatus = savePrescription.getAtatus();//检查状态
        Date acreatetime = savePrescription.getAcreatetime();//创建时间

        return null;
    }*/
}
